]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionDownloader: Check schemadir existence and type
authorAndy Holmes <andyholmes@gnome.org>
Mon, 27 Mar 2023 19:41:50 +0000 (12:41 -0700)
committerMarge Bot <marge-bot@gnome.org>
Mon, 27 Mar 2023 21:12:59 +0000 (21:12 +0000)
When checking for an extension schemadir, an error will be thrown if
`query_info()` is used and the directory is missing.

Catch the case of a missing directory, but throw an error if the
path exists as a non-directory type.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2727>

js/ui/extensionDownloader.js

index b3cef41a6aedf36863366de1d0260fe26898d3da..197cc1c1cf98232d365d210dd51a5ff4da346af1 100644 (file)
@@ -115,21 +115,30 @@ async function extractExtensionArchive(bytes, dir) {
     await unzip.wait_check_async(null);
 
     const schemasPath = dir.get_child('schemas');
-    const info = await schemasPath.query_info_async(
-        Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
-        Gio.FileQueryInfoFlags.NONE,
-        GLib.PRIORITY_DEFAULT,
-        null);
-
-    if (info.get_file_type() === Gio.FileType.DIRECTORY) {
-        const compileSchema = Gio.Subprocess.new(
-            ['glib-compile-schemas', '--strict', schemasPath.get_path()],
-            Gio.SubprocessFlags.NONE);
-        try {
-            await compileSchema.wait_check_async(null);
-        } catch (e) {
-            log(`Error while compiling schema for extension ${dir.get_basename()}: (${e.message})`);
-        }
+
+    try {
+        const info = await schemasPath.query_info_async(
+            Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
+            Gio.FileQueryInfoFlags.NONE,
+            GLib.PRIORITY_DEFAULT,
+            null);
+
+        if (info.get_file_type() !== Gio.FileType.DIRECTORY)
+            throw new Error('schemas is not a directory');
+    } catch (e) {
+        if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND))
+            console.warn(`Error while looking for schema for extension ${dir.get_basename()}: ${e.message}`);
+        return;
+    }
+
+    const compileSchema = Gio.Subprocess.new(
+        ['glib-compile-schemas', '--strict', schemasPath.get_path()],
+        Gio.SubprocessFlags.NONE);
+
+    try {
+        await compileSchema.wait_check_async(null);
+    } catch (e) {
+        log(`Error while compiling schema for extension ${dir.get_basename()}: (${e.message})`);
     }
 }